package likou;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2020/10/12 07:30
 */
public class _530 {
    static int pre;
    static int ans;

    public static void main(String[] args) {
        TreeNode treeNode =new TreeNode(1);
        treeNode.right=new TreeNode(3);
        treeNode.right.left=new TreeNode(2);
        System.out.println(getMinimumDifference(treeNode));
    }

    public static int getMinimumDifference(TreeNode root) {
        ans = Integer.MAX_VALUE;
        pre = -1;
        dfs(root);
        return ans;
    }

    public static void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        dfs(root.left);
        if (pre == -1) {
            pre = root.val;
        } else {
            ans = Math.min(ans, root.val - pre);
            pre = root.val;
        }
        dfs(root.right);
    }
}